/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaUploadImage from "@/components/ma-upload-image/index.vue";
import { concat } from "lodash-es";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { userList } from "$/attractions/commerce/api/commerceMerchant.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "管理员",
      prop: "admin_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: userList,
        axiosConfig: {
          params: { page: 1, limit: 1000 },
        },
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.username || `管理员${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择管理员",
        clearable: true,
        filterable: true,
        multiple: false,
        // 无障碍访问属性
        "aria-label": "选择管理员",
        role: "combobox",
      },
      itemProps: { rules: [{ required: true, message: "请选择管理员" }] },
    },
    {
      label: "商户名称",
      prop: "merchant_name",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "商户名称" }),
      },
    },
    {
      label: "商户类型",
      prop: "merchant_type",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "个体户", value: 1 },
          { label: "企业", value: 2 },
          { label: "虚拟商户", value: 3 },
          { label: "合作社", value: 4 },
          { label: "政府单位", value: 5 },
        ],
        placeholder: t("form.pleaseInput", { msg: "商户类型" }),
        clearable: true,
        filterable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择商户类型" }] },
    },
    {
      label: "法人代表",
      prop: "legal_person",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "法人代表" }) },
    },
    {
      label: "法人联系方式",
      prop: "legal_person_phone",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "法人联系方式" }),
      },
    },
    {
      label: "法人身份证",
      prop: "legal_person_id_card",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "法人身份证" }),
      },
    },
    {
      label: "商户联系人",
      prop: "contact_person",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "商户联系人" }),
      },
    },
    {
      label: "商户联系电话",
      prop: "contact_phone",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "商户联系电话" }),
      },
    },
    {
      label: "联系邮箱",
      prop: "contact_email",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "联系邮箱" }) },
    },
    {
      label: "商店地址",
      prop: "address",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "商店地址" }) },
    },
    {
      label: "经营范围",
      prop: "business_scope",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "经营范围" }) },
    },
    {
      label: "商户开门时间",
      prop: "open_time",
      render: "TimePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "商户开门时间" }),
        valueFormat: "HH:mm:ss",
        format: "HH:mm:ss",
      },
    },
    {
      label: "商户关门时间",
      prop: "close_time",
      render: "TimePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "商户关门时间" }),
        valueFormat: "HH:mm:ss",
        format: "HH:mm:ss",
      },
    },
    {
      label: "注册资本",
      prop: "registered_capital",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "注册资本" }) },
    },
    {
      label: "成立日期",
      prop: "established_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "成立日期" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: false,
    },
    {
      label: "营业执照照片",
      prop: "business_license_url",
      render: () => MaUploadImage,
      renderProps: {
        placeholder: "请上传营业执照照片",
        multiple: false,
        limit: 1,
        accept: "image/*",
        tips: "支持jpg、png、gif格式，文件大小不超过5MB",
      },
    },
    {
      label: "营业执照号",
      prop: "business_license",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "营业执照号" }),
      },
    },
    {
      label: "税务登记号",
      prop: "tax_id",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "税务登记号" }),
      },
    },
    {
      label: "开户银行",
      prop: "bank_name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "开户银行" }) },
    },
    {
      label: "银行账号",
      prop: "bank_account",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "银行账号" }) },
    },
  ]);
}
